Type CGNodes Extends CUI

	Field nexty:Int = 0

	Method init(p:CUI=Null)
		
		Local gads:TGadget[10]
		window = CreateWindow("Node Manager", 10, 10, 256, 512,Null,WINDOW_TITLEBAR|WINDOW_TOOL|WINDOW_CENTER )
		gads[0] = CreateLabel("Node Types",5,5,ClientWidth(window)-10,20,window)
		nexty = 5+GadgetHeight(gads[0])
		gads[1] = CreateComboBox(5,nexty,ClientWidth(window)-10,25,window)
		nexty = nexty+5+GadgetHeight(gads[1])
		gads[2] = CreateButton("Add to Map",5,nexty,ClientWidth(window)-5,30,window)
		AddGadgetItem(gads[1],"Generic Node",0,-1,"")
		AddGadgetItem(gads[1],"Omni Light",0,-1,"")
		AddGadgetItem(gads[1],"Point Light",0,-1,"")
		AddGadgetItem(gads[1],"Spot Light",0,-1,"")
		AddGadgetItem(gads[1],"Sound Node",0,-1,"")
		AddGadgetItem(gads[1],"Camera Node",0,-1,"")
		SelectGadgetItem(gads[1],0)
		
		gadgets = gads
		
	
		Super.Init(p)
	EndMethod

	Method Update(EID:Int)

		Select EID
			Case EVENT_GADGETACTION
				Select EventSource()

					Case gadgets[2]
						If SelectedGadgetItem(gadgets[1]) <> -1 Then
							AddtoMap(SelectedGadgetItem(gadgets[1]))
						
						EndIf
				EndSelect
			Case EVENT_WINDOWCLOSE
				Select EventSource()

		
					Case window
						If Parent <> Null Then
							'ListRemove(Parent.Children,Self)
							
						EndIf	
						'FreeGadget(window)
						HideGadget(window)
				EndSelect

		
		
		End Select
		Super.Update(EID)
	EndMethod

	Method AddtoMap(item:Int)
		Local m:MapObject = New MapObject
		Local moNode:xmlNode = CURRENTMAP.Root().AddNode("GameObject",AS_CHILD)
		m.node = moNode
		ListAddLast(MapObjects,m)
		Select item
		
			Case 0
				m.Mesh = CreateCube()
				moNode.Attribute("type").Value = "general"
				m.name = "General "+CountList(MapObjects)
				
			Case 1
				m.Mesh  = CreateLight(1)
				moNode.Attribute("type").Value = "omnilight"
				m.name = "Omni Light "+CountList(MapObjects)
			Case 2
				m.Mesh  = CreateLight(2)
				moNode.Attribute("type").Value = "pointlight"
				m.name = "Point Light "+CountList(MapObjects)
			Case 3
				m.Mesh  = CreateLight(3)
				moNode.Attribute("type").Value = "spotlight"
				m.name = "Spot Light "+CountList(MapObjects)
			Case 4
				m.Mesh  = CreatePivot()
				moNode.Attribute("type").Value = "sound"
				m.name = "3d Sound "+CountList(MapObjects)
			Case 5
				m.Mesh  = CreateCamera()
				CameraViewport TCamera(m.Mesh),10,10,320,240
				HideEntity(m.Mesh)
				moNode.Attribute("type").Value = "camera"
				m.name = "Camera "+CountList(MapObjects)
								
		EndSelect
		moNode.Attribute("name").Value = m.name
		MainEditor.MainUI.RefreshSceneList()

	EndMethod

End Type